import * as actionTypes from "./constance";
import { getHotAlbum, getNewAlbum, getAlbumNewest } from "@/services/album";

const hotTopAlbum = (res) => ({
  type: actionTypes.GET_TOPALBUM,
  topAlbums: res,
});

const newAlbum = (res) => ({
  type: actionTypes.GET_ALBUMNEW,
  albumNews: res,
});
const AlbumNewest = (res) => ({
  type: actionTypes.GET_ALBUMNEWEST,
  AlbumNewests: res,
});

export const hotTopAlbumAction = (limit, type) => {
  return (dispatch) => {
    getHotAlbum(limit, type).then((res) => {
      dispatch(hotTopAlbum(res));
    });
  };
};

export const newAlbumAction = (limit, offset, area) => {
  return (dispatch) => {
    getNewAlbum(limit, offset, area).then((res) => {
      dispatch(newAlbum(res));
    });
  };
};

export const albumNewestAction = () => {
  return (dispatch) => {
    getAlbumNewest().then((res) => {
      dispatch(AlbumNewest(res));
    });
  };
};
